<?php

/**
 * This is the model class for table "cargo_export".
 *
 * The followings are the available columns in table 'cargo_export':
 * @property integer $id
 * @property integer $cargo_id
 * @property integer $export_information_id
 * @property string $remark
 * @property integer $export_id
 */
class cargo_export extends ActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return cargo_export the static model class
	 */
	public $exporter;
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cargo_export';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cargo_id, export_information_id', 'required'),
			array('cargo_id, export_information_id', 'numerical', 'integerOnly'=>true),
			array('export_information_id','exist','className'=>'export_information','attributeName'=>'id'),
			array('cargo_id','exist','className'=>'cargo','attributeName'=>'id'),
                        array('cargo_id', 'unique', 'allowEmpty' => false),
			array('exporter_ref,remark', 'length', 'max'=>512),
			array('exporter,consignee','safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, cargo_id, export_information_id, remark, export_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cargo'=>array(self::BELONGS_TO,'cargo','cargo_id'),
			'export'=>array(self::BELONGS_TO,'export_information','export_information_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cargo_id' => 'Cargo',
			'export_information_id' => 'Export Information',
			'remark' => 'Remark',
			'export_id' => 'Export',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('cargo_id',$this->cargo_id);

		$criteria->compare('export_information_id',$this->export_information_id);

		$criteria->compare('remark',$this->remark,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	public function in_export($id){
		$this->export_information_id = $id;
		return $this->search();
	}
}